package com.gqr.threadlocal;

import javax.lang.model.element.VariableElement;

/**
 * Copyright (C), 2020-2024,gqr
 * FileName:ThreadLocalNPE
 * author:guqingrong
 * Date:2024-05-09 21:55
 * Description:ThreadLocal 空指针
 * History:
 * <author>    <time>    <version>    <desc>
 * 作者姓名     修改时间     版本号        描述
 */
public class ThreadLocalNPE {
    ThreadLocal<Long> longThreadLocal = new ThreadLocal<Long>();

    public void set(){
        longThreadLocal.set(Thread.currentThread().getId());
    }

    public Long get(){
        return longThreadLocal.get();
    }

    public static void main(String[] args) {
        ThreadLocalNPE threadLocalNPE = new ThreadLocalNPE();
        System.out.println(threadLocalNPE.get());
        Thread thread1 = new Thread(new Runnable(){

            @Override
            public void run() {
                threadLocalNPE.set();

                System.out.println(threadLocalNPE.get());
            }
        });
        thread1.start();

//        threadLocalNPE.set();
//        System.out.println(threadLocalNPE.get());
    }

}
